import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import vueJsx from '@vitejs/plugin-vue-jsx';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';
import { viteMockServe } from 'vite-plugin-mock';
import { resolve } from 'path';

export default defineConfig(({ mode }) => ({
  // base:'/demo',
  esbuild: {
    drop: mode === 'production' ? ['console', 'debugger'] : [],
  },
  plugins: [
    vue(),
    vueJsx(),
    viteMockServe({ logger: false, mockPath: './mock/' }),
    Components({
      dirs: ['src/components', 'src/layout'],
      resolvers: [VantResolver()],
    }),
  ],
  resolve: {
    alias: [
      {
        find: '@',
        replacement: resolve(__dirname, './src'),
      },
      {
        find: '#',
        replacement: resolve(__dirname, './typings'),
      },
    ],
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "./variable.scss" as *;',
        silenceDeprecations: ['legacy-js-api'], // 加载全局样式，使用scss特性
      },
    },
  },
  server: {
    port: 80,
    host: '0.0.0.0',
    cors: true,
    proxy: {
      // "/test": {
      //   target: "http://192.168.0.0:8080", //目标url
      //   changeOrigin: true, //支持跨域
      // },
    },
  },
}));
